﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.Data;

public partial class BarCodePrintOut : ExtBaseRpt
{
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        if (!X.IsAjaxRequest)
        {
            InsActLog(mid, "浏览");
            //加载条件控件 
            this.txtYearNo.GetStore().DataSource = db.DM_GetDateSet("SELECT DISTINCT YearNo FROM dbo.KM_V_Mat ORDER BY YearNo ");
            this.txtSeasonName.GetStore().DataSource = db.DM_GetDateSet("SELECT DISTINCT SeasonName FROM dbo.KM_V_Mat ");
            this.txtKindName.GetStore().DataSource = db.DM_GetDateSet("SELECT DISTINCT KindName FROM dbo.KM_V_Mat ");
        }
    }

    protected void RefreshDataSet(object sender, StoreReadDataEventArgs e)
    {
        BtnQureyUser4(null, null);
    }

    protected void Store4_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        ExtGridToExcel(mid, "xls", e.Xml, this.Response, "月度回货计划表");
    }

    /// <summary>
    /// 月度回货计划列表数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnQureyUser4(object sender, DirectEventArgs e)
    {
        try
        {
            DataSet ds = GetMonthlyReturnPlan();
            this.Store3.DataSource = ds;
            this.Store3.DataBind();
        }
        catch (Exception ex)
        {
            Activity.Log.Error("请求产品包装信息异常：" + ex);
        }
    }

    protected void BtnOutExcel(object sender, DirectEventArgs e)
    {
        //导出EXCEL
        try
        {
            DataSet ds = GetMonthlyReturnPlan();
            string path = NpoiHelper.ExportByWeb(mid, ds, this.Title);
            this.ResourceManager1.AddScript("outExcle('" + path + "')");
        }
        catch (Exception ex)
        {
            Activity.Log.Error("请求报表数据异常：" + ex);
            ShowBox("导出出错：" + ex.Message);
        }
    }

    //获取条码打印输出数据信息
    public DataSet GetMonthlyReturnPlan()
    {
        try
        {
            string YearNo = StrSplitParam(this.txtYearNo); //年份
            string SeasonName = StrSplitParam(this.txtSeasonName); //季节
            string DateBegin = this.txtDateBegin.Text; //开始日期
            string DateEnd = this.txtDateEnd.Text; //结束时间
            string VendcustCode = this.txtVendcustCode.Text; //供应商编号
            string VendCustName = this.txtVendCustName.Text; //供应商名称
            string StyleCode = this.txtStyleCode.Text; //款号
            string KindName = StrSplitParam(this.txtKindName); //大类
            string BillNo = this.txtBillNo.Text; //单号
            string FactCode = this.txtFactCode.Text; //制单号
            string MatVendor = this.txtMatVendor.Text; //物料供应商
            string MatBillCode = this.txtMatBillCode.Text; //物料采购单号
            string MaterialCode = this.txtMaterialCode.Text; //货号
            string BarCode = this.txtBarCode.Text; //条码 


            string sqlWhere = string.Empty;
            if (!string.IsNullOrEmpty(YearNo))
            {
                sqlWhere += string.Format(@" AND StockID IN {0} ", YearNo);
            }
            if (!string.IsNullOrEmpty(KindName))
            {
                sqlWhere += string.Format(@" AND KindName IN {0} ", KindName);
            }
            if (!string.IsNullOrEmpty(SeasonName))
            {
                sqlWhere += string.Format(@" AND OrderType IN {0} ", SeasonName);
            }

            if (Convert.ToDateTime(DateBegin) == Convert.ToDateTime("0001-01-01 00:00:00"))
            {
                ShowBox("请选择开始日期！");
                return null;
            }
            if (Convert.ToDateTime(DateEnd) == Convert.ToDateTime("0001-01-01 00:00:00"))
            {
                ShowBox("请选择结束时间！");
                return null;
            }

            var UserID = this.UserId;
            string whereSql = string.Format(@"KM_PurDetailBarCode_NewPrint '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}'",
                YearNo, SeasonName, DateBegin, DateEnd, VendcustCode, VendCustName, StyleCode, KindName, BillNo, FactCode, MatVendor, MatBillCode, MaterialCode, BarCode, UserID);
            DataSet ds = db.DM_GetDateSet(whereSql);
            return ds;

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}